home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++
- Subject: Re: Scope/longevity of class statics
- Date: Thu, 15 Feb 1996 17:41:11 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4fvr6l$m1l@news.halcyon.com>
- References: <4fu0qc$1h0@news.dcccd.edu>
- NNTP-Posting-Host: blv-pm10-ip5.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- bcalbridge@dcccd.edu (Bob Calbridge) wrote:
-
- >I know this sounds odd but since things didn't seem to work as
- >expected I'll put the question to the newsgroup. I have some
- >class static data that represents an upper left corner offset
- >for all display data. In order to set the value I applied it
- >to a temporary class object inside a function. It seemed to
- >work find for my purposes. However, when I moved the code that
- >set the values to another function that was invoked prior to the
- >original function where it was instigated the values ended up
- >improperly set by the time I got to my main code.
-
- >Does class static data only have scope where the object that
- >was used to set it has scope? This doesn't sound right to me
- >but it seems as if that's the way it's behaving.
- >--
- >=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- >- Bob Calbridge = Dallas County Community College District -
- >= bcalbridge@dcccd.edu PC Systems Programmer =
- >- Postmaster -
- >=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- > Patience is a virtue. It's not a job requirement.
-
- If I understand you, you had code like
-
- class CMyDataView
- {
- ...
- public:
- static int s_xorigin;
- static int s_yorigin;
- };
-
- int CMyDataView::s_xorigin;
- int CMyDataView::s_yorigin;
-
- void draw()
- {
- CMyDataView myView;
- myView.s_xorigin = 10; // This worked
- myView.s_yorigin. = 20;
- ...
- }
-
- then you moved the initialization code to
-
- void init()
- {
- CMyDataView myView;
- myView.s_xorigin = 10;
- myView.s_yorigin. = 20;
- // or maybe CMyDataView::s_xorigin = 10; etc.
- }
-
- void main()
- {
- init();
- draw();
- }
-
- and you find that it failed?
-
- Static data has global scope; this should have succeeded. Is there
- anything more complex going on here? Marshalling over OLE? Sharing
- the CMyDataView DLL among multple processes and hoping the static
- variable memory is also shared?
-
- --Norm
-
-